import createDOMElement from './createDOMElement'
import unmountNode from './unmountNode'

export default function mountNativeElement(virtualDOM, container, oldDOM) {
    const newElement = createDOMElement(virtualDOM)

    if(oldDOM) {
        container.insertBefore(newElement, oldDOM)
    }else{
        container.appendChild(newElement)
    }

    if(oldDOM) {
        unmountNode(oldDOM)
    }

    // 获取组件实例对象，如果存在，将DOM对象存储在类组件实例对象中
    let component = virtualDOM.component
    if(component){
        component.setDOM(newElement)
    }
}